package ru.tpu.osu.faces.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import ru.tpu.osu.faces.dao.*;

@FacesConverter(forClass=Subject.class)
public class SubjectConverter implements Converter  {

	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		Subject s = (Subject) HibernateUtil.getSession().get(Subject.class, Integer.parseInt(arg2));
		return s;
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		Subject s = (Subject)arg2;
		return s.getId()+"";
	}

}
